import java.util.Iterator;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;


public class XMLTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Element elem = null ;
        //1.取得某节点下的某属性
		Document document = DocumentHelper.createDocument(); 
        Element root=document.getRootElement(); 
        
        elem = root.addElement("root") ;
        
        root.addAttribute("name", "test") ;
        elem = elem.addElement("user") ;
        elem = elem.addElement("name") ;
        elem.addCDATA("cxr") ;
        
        elem = elem.addElement("age") ;
        elem.addCDATA("18") ;
        
        String xmlString = root.asXML() ;

        System.out.println(xmlString) ;
    }

}
